In numerical analysis, Simpson's rule is a method for numerical integration, the numerical approximation of definite integrals. Specifically, it is the following approximation:
Simpson's rule also corresponds to the 3-point Newton-Cotes quadrature rule.
The method is credited to the mathematician Thomas Simpson (1710–1761) of Leicestershire, England. Kepler used similar formulas over 100 years prior and in German the method is sometimes called Keplersche Fassregel for this reason.
Simpson's rule is a staple of scientific data analysis and engineering. It is widely used, for example, by Naval architects to calculate the capacity of a ship or lifeboat.[1]
Contents |
Simpson's rule can be derived in various ways.
One derivation replaces the integrand by the quadratic polynomial which takes the same values as at the end points a and b and the midpoint m = (a + b) / 2. One can use Lagrange polynomial interpolation to find an expression for this polynomial,
An easy (albeit tedious) calculation shows that
This calculation can be carried out more easily if one first observes that (by scaling) there is no loss of generality in assuming that and .
Another derivation constructs Simpson's rule from two simpler approximations: the midpoint rule
and the trapezoidal rule
The errors in these approximations are
respectively. It follows that the leading error term vanishes if we take the weighted average
This weighted average is exactly Simpson's rule.
Using another approximation (for example, the trapezoidal rule with twice as many points), it is possible to take a suitable weighted average and eliminate another error term. This is Romberg's method.
The third derivation starts from the ansatz
The coefficients α, β and γ can be fixed by requiring that this approximation be exact for all quadratic polynomials. This yields Simpson's rule.
The error in approximating an integral by Simpson's rule is
where is some number between and .[3]
The error is asymptotically proportional to . However, the above derivations suggest an error proportional to . Simpson's rule gains an extra order because the points at which the integrand is evaluated are distributed symmetrically in the interval [a, b].
Since the error term is proportional to the fourth derivative of f at , this shows that Simpson's rule provides exact results for any polynomial f of degree three or less, since the fourth derivative of such a polynomial is zero at all points.
If the interval of integration is in some sense "small", then Simpson's rule will provide an adequate approximation to the exact integral. By small, what we really mean is that the function being integrated is relatively smooth over the interval . For such a function, a smooth quadratic interpolant like the one used in Simpson's rule will give good results.
However, it is often the case that the function we are trying to integrate is not smooth over the interval. Typically, this means that either the function is highly oscillatory, or it lacks derivatives at certain points. In these cases, Simpson's rule may give very poor results. One common way of handling this problem is by breaking up the interval into a number of small subintervals. Simpson's rule is then applied to each subinterval, with the results being summed to produce an approximation for the integral over the entire interval. This sort of approach is termed the composite Simpson's rule.
Suppose that the interval is split up in subintervals, with an even number. Then, the composite Simpson's rule is given by
where for with ; in particular, and . The above formula can also be written as
The error committed by the composite Simpson's rule is bounded (in absolute value) by
where is the "step length", given by [4]
This formulation splits the interval in subintervals of equal length. In practice, it is often advantageous to use subintervals of different lengths, and concentrate the efforts on the places where the integrand is less well-behaved. This leads to the adaptive Simpson's method.
This is another formulation of a composite Simpson's rule: instead of applying Simpson's rule to disjoint segments of the integral to be approximated, Simpson's rule is applied to overlapping segments, yielding:[5]
Simpson's 3/8 rule is another method for numerical integration proposed by Thomas Simpson. It is based upon a cubic interpolation rather than a quadratic interpolation. Simpson's 3/8 rule is as follows:
The error of this method is:
where is some number between and . Thus, the 3/8 rule is about twice as accurate as the standard method, but it uses one more function value. A composite 3/8 rule also exists, similarly as above.[6]
An implementation of the composite Simpson's rule in pylab:
def simpson(f, a, b, n): """f=function, a=initial value, b=end value, n=number of double intervals of size 2h""" n *= 2 h = (b - a) / n; S = f(a) for i in range(1, n, 2): x = a + h * i S += 4 * f(x) for i in range(2, n-1, 2): x = a + h * i S += 2 * f(x) S += f(b) F = h * S / 3 return F
This article incorporates material from Code for Simpson's rule on PlanetMath, which is licensed under the Creative Commons Attribution/Share-Alike License.